package com.houdoudou.servlet.app;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.houdoudou.affair.app.CustomerAffairApp1;
import com.houdoudou.affair.app.MachineAffairApp1;
import com.houdoudou.bean.AppBack;

public class Machine4App extends HttpServlet {
	private static final long serialVersionUID = 519L;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		process(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		process(req, resp);
	}
	

	void process(HttpServletRequest req, HttpServletResponse resp) throws IOException{
		
		String affair="";
		    try {
				req.setCharacterEncoding("UTF-8");
				  resp.setCharacterEncoding("UTF-8");
					 affair=req.getParameter("affair");
					 System.out.println("\n");
					 System.out.println("affair="+affair + "  时间----"+ new Date());
					 System.out.println("");
		    } catch (UnsupportedEncodingException e) {
		    	
		    }		    
		    //自提柜登陆
			 if(affair.equals("login")){ 
				MachineAffairApp1.login(req, resp);
			 }//根据自提柜查询商家
			 else  if(affair.equals("frequentlyPull")){ 
					MachineAffairApp1.frequentlyPull(req, resp);
				 } //通用函数，改变订单状态
			 else  if(affair.equals("changeOrderState")){ 
					MachineAffairApp1.changeOrderState(req, resp);
				 }// 快递员登陆自提柜
			 else  if(affair.equals("courierLogin")){ 
					MachineAffairApp1.courierLogin(req, resp);
				 }//  订单需要增加箱格
			 else  if(affair.equals("addBox")){ 
					MachineAffairApp1.addBox(req, resp);
				 } //  删除多余箱格
			 else  if(affair.equals("deleteBox")){ 
					MachineAffairApp1.deleteOrLockBox(req, resp, false);
				 }//  锁定箱格
			 else  if(affair.equals("lockBoxInUsing")){ 
					MachineAffairApp1.deleteOrLockBox(req, resp, true);
				 }//  订单送达
			 else  if(affair.equals("orderArrive")){ 
					MachineAffairApp1.orderArrive(req, resp);
				 } //  取回订单
			 else  if(affair.equals("orderTakeback")){ 
					MachineAffairApp1.orderTakeback(req, resp);
				 } //  丢弃订单
			 else  if(affair.equals("abandomOrder")){ 
					MachineAffairApp1.orderAbandom(req, resp);
				 }//  取走订单
			 else  if(affair.equals("orderTaked")){ 
					MachineAffairApp1.orderTaked(req, resp);
				 }			 
			 else{
				 new AppBack(req, resp ).send(1, "事件未定义");
			 }
	}
}
